#include "List.h"


function addString(char ptr elem)
{
    struct StringNode ptr node = newStringNode;
    node-> element = elem;

    if(StringListHead equ NULL)
    {
        StringListHead = node;
        StringListTail = StringListHead;
        stringListLength = 1;
    }
    else
    {
        StringListTail-> next = node;
        StringListTail = StringListTail-> next;
        stringListLength = stringListLength + 1;
    }
}

function clearStringList()
{
    if(StringListHead neq NULL)
    {
        struct StringNode ptr node = StringListHead;
        int i = 0;
        while(node neq StringListTail-> next)
        {
            printf("Clear Element %d: %s\n", i, node-> element);
            struct StringNode ptr tmp = node;
            node = node-> next;
            free(tmp-> element);
            free(tmp);
            i = i + 1;
        }
    }
    resetStringListPtr();
}

function printStringList()
{
    if(StringListHead neq NULL)
    {
        struct StringNode ptr node = StringListHead;
        int i = 0;
        while(node neq StringListTail-> next)
        {
            printf("Element %d: %s\n", i, node-> element);
            node = node-> next;
            i = i + 1;
        }
    }
}

int hasNextString()
{
    if(StringListCurrent equ StringListTail)
    {
        return 0;
    }
    else
    {
        return 1;
    }
}

char ptr getNextString()
{
    if(StringListCurrent equ NULL)
    {
        StringListCurrent = StringListHead;
    }
    elif(StringListCurrent neq StringListTail)
    {
        StringListCurrent = StringListCurrent-> next;
    }
    else
    {
        printf("This should not happen");
    }
    return StringListCurrent-> element;
}

function resetStringListPtr()
{
    StringListCurrent = NULL;
}
